from PyQt5 import QtCore, QtGui, QtWidgets
import sys,os


class Ui_AttackStrategyConfig(object):
    def setupUi(self, AttackStrategyConfig):
        AttackStrategyConfig.setObjectName("AttackStrategyConfig")
        AttackStrategyConfig.resize(500, 600)
        self.centralwidget = QtWidgets.QWidget(AttackStrategyConfig)
        self.centralwidget.setGeometry(QtCore.QRect(0, 0, 490, 590))
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setSpacing(15)
        self.verticalLayout.setObjectName("verticalLayout")
        # 设置icon图标
        filename = self.resource_path(os.path.join('Pictures','attacker.ico'))
        AttackStrategyConfig.setWindowIcon(QtGui.QIcon(filename))
        # 设置窗口标题栏样式
        AttackStrategyConfig.setStyleSheet("""
            QMainWindow {
                background-color: #f0f0f0;
                border-radius: 10px;
            }
            QLabel {
                color: #333333;
                font-size: 14px;
                font-family: Arial, sans-serif;
            }
            QLineEdit {
                background-color: white;
                border: 1px solid #cccccc;
                border-radius: 5px;
                padding: 5px;
                font-size: 14px;
            }
            QDoubleSpinBox {
                background-color: white;
                border: 1px solid #cccccc;
                border-radius: 5px;
                padding: 5px;
                font-size: 14px;
            }
            QPushButton {
                background-color: #4a90e2;
                color: white;
                border: none;
                border-radius: 5px;
                padding: 10px 20px;
                font-size: 14px;
                font-weight: bold;
            }
            QPushButton:hover {
                background-color: #357abd;
            }
        """)

        self.label_DosP = QtWidgets.QLabel(self.centralwidget)
        self.label_DosP.setObjectName("label_DosP")
        self.label_DosP.setStyleSheet("font-size: 14px; font-weight: bold;")
        self.verticalLayout.addWidget(self.label_DosP)
        self.lineEdit_DosP = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_DosP.setObjectName("lineEdit_DosP")
        self.lineEdit_DosP.setStyleSheet("padding: 5px;")
        self.verticalLayout.addWidget(self.lineEdit_DosP)
        self.label_Ff = QtWidgets.QLabel(self.centralwidget)
        self.label_Ff.setObjectName("label_Ff")
        self.verticalLayout.addWidget(self.label_Ff)
        self.doubleSpinBox_Ff = QtWidgets.QDoubleSpinBox(self.centralwidget)
        self.doubleSpinBox_Ff.setDecimals(2)
        self.doubleSpinBox_Ff.setMinimum(0.01)
        self.doubleSpinBox_Ff.setMaximum(1.0)
        self.doubleSpinBox_Ff.setProperty("value", 0.1)
        self.doubleSpinBox_Ff.setObjectName("doubleSpinBox_Ff")
        self.doubleSpinBox_Ff.setSingleStep(0.01)
        self.doubleSpinBox_Ff.setStyleSheet("padding: 5px;")
        self.verticalLayout.addWidget(self.doubleSpinBox_Ff)
        self.label_Impersonation = QtWidgets.QLabel(self.centralwidget)
        self.label_Impersonation.setObjectName("label_Impersonation")
        self.verticalLayout.addWidget(self.label_Impersonation)
        self.doubleSpinBox_Impersonation = QtWidgets.QDoubleSpinBox(self.centralwidget)
        self.doubleSpinBox_Impersonation.setDecimals(2)
        self.doubleSpinBox_Impersonation.setMinimum(0.01)
        self.doubleSpinBox_Impersonation.setMaximum(1.0)
        self.doubleSpinBox_Impersonation.setProperty("value", 0.3)
        self.doubleSpinBox_Impersonation.setSingleStep(0.01)
        self.doubleSpinBox_Impersonation.setObjectName("doubleSpinBox_Impersonation")
        self.doubleSpinBox_Impersonation.setStyleSheet("padding: 5px;")
        self.verticalLayout.addWidget(self.doubleSpinBox_Impersonation)
        self.label_FDI = QtWidgets.QLabel(self.centralwidget)
        self.label_FDI.setObjectName("label_FDI")
        self.verticalLayout.addWidget(self.label_FDI)
        self.doubleSpinBox_FDI = QtWidgets.QDoubleSpinBox(self.centralwidget)
        self.doubleSpinBox_FDI.setDecimals(2)
        self.doubleSpinBox_FDI.setMinimum(0.01)
        self.doubleSpinBox_FDI.setMaximum(1.0)
        self.doubleSpinBox_FDI.setObjectName("doubleSpinBox_FDI")
        self.doubleSpinBox_FDI.setSingleStep(0.01)
        self.doubleSpinBox_FDI.setStyleSheet("padding: 5px;")
        self.verticalLayout.addWidget(self.doubleSpinBox_FDI)
        self.label_AA_Signal = QtWidgets.QLabel(self.centralwidget)
        self.label_AA_Signal.setObjectName("label_AA_Signal")
        self.verticalLayout.addWidget(self.label_AA_Signal)
        self.doubleSpinBox_AA_Signal = QtWidgets.QDoubleSpinBox(self.centralwidget)
        self.doubleSpinBox_AA_Signal.setDecimals(3)
        self.doubleSpinBox_AA_Signal.setMinimum(0.01)
        self.doubleSpinBox_AA_Signal.setMaximum(1.0)
        self.doubleSpinBox_AA_Signal.setSingleStep(0.001)
        self.doubleSpinBox_AA_Signal.setObjectName("doubleSpinBox_AA_Signal")
        self.doubleSpinBox_AA_Signal.setStyleSheet("padding: 5px;")
        self.verticalLayout.addWidget(self.doubleSpinBox_AA_Signal)
        self.label_AA_Rate = QtWidgets.QLabel(self.centralwidget)
        self.label_AA_Rate.setObjectName("label_AA_Rate")
        self.verticalLayout.addWidget(self.label_AA_Rate)
        self.doubleSpinBox_AA_Rate = QtWidgets.QDoubleSpinBox(self.centralwidget)
        self.doubleSpinBox_AA_Rate.setReadOnly(True)
        self.doubleSpinBox_AA_Rate.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons)
        self.doubleSpinBox_AA_Rate.setDecimals(3)
        self.doubleSpinBox_AA_Rate.setMinimum(0.01)
        self.doubleSpinBox_AA_Rate.setMaximum(1.0)
        self.doubleSpinBox_AA_Rate.setSingleStep(0.001)
        self.doubleSpinBox_AA_Rate.setProperty("value", 0.036)
        self.doubleSpinBox_AA_Rate.setObjectName("doubleSpinBox_AA_Rate")
        self.doubleSpinBox_AA_Rate.setStyleSheet("padding: 5px;")
        self.verticalLayout.addWidget(self.doubleSpinBox_AA_Rate)
        self.label_AA_Rate_Hint = QtWidgets.QLabel(self.centralwidget)
        self.label_AA_Rate_Hint.setObjectName("label_AA_Rate_Hint")
        self.label_AA_Rate_Hint.setStyleSheet("color: gray; font-size: 12px;")
        self.verticalLayout.addWidget(self.label_AA_Rate_Hint)
        self.submitBtn = QtWidgets.QPushButton(self.centralwidget)
        self.submitBtn.setObjectName("submitBtn")
        self.submitBtn.setFixedSize(200, 50)
        self.verticalLayout.addWidget(self.submitBtn)
        self.submitBtn.setStyleSheet("background-color: #4CAF50; padding: 10px 20px; font-size: 16px; font-weight: bold; border-radius: 5px;")

        # 创建一个水平布局用于底部按钮
        self.bottom_layout = QtWidgets.QHBoxLayout()
        self.bottom_layout.addStretch(1)  # 添加伸展因子，使按钮居中
        self.bottom_layout.addWidget(self.submitBtn)
        self.bottom_layout.addStretch(1)  # 添加伸展因子，使按钮居中
        # 将水平布局添加到垂直布局的底部
        self.verticalLayout.addLayout(self.bottom_layout)

        self.retranslateUi(AttackStrategyConfig)
        QtCore.QMetaObject.connectSlotsByName(AttackStrategyConfig)
    def resource_path(self, relative_path):
        if getattr(sys, 'frozen', False):
            base_path = sys._MEIPASS
        else:
            base_path = "./"
        ret_path = os.path.join(base_path, relative_path)
        return ret_path
    def retranslateUi(self, AttackStrategyConfig):
        _translate = QtCore.QCoreApplication.translate
        AttackStrategyConfig.setWindowTitle(_translate("AttackStrategyConfig", "攻击策略配置"))
        self.label_DosP.setText(_translate("AttackStrategyConfig", "Dos攻击周期（格式如1-5,10-15）:"))
        self.lineEdit_DosP.setPlaceholderText(_translate("AttackStrategyConfig", "请输入周期，如1.11-5,11-15.3。不输入采取默认值"))
        self.label_Ff.setText(_translate("AttackStrategyConfig", "Dos攻击频率约束参数Fa:"))
        self.label_Impersonation.setText(_translate("AttackStrategyConfig", "伪装攻击信号幅值:"))
        self.label_FDI.setText(_translate("AttackStrategyConfig", "虚假注入攻击信号幅值:"))
        self.label_AA_Signal.setText(_translate("AttackStrategyConfig", "执行器攻击信号幅值:"))
        self.label_AA_Rate.setText(_translate("AttackStrategyConfig", "执行器攻击变化速率上限:"))
        self.label_AA_Rate_Hint.setText(_translate("AttackStrategyConfig", "该项由执行器攻击信号幅值计算得出，不能手动输入"))
        self.submitBtn.setText(_translate("AttackStrategyConfig", "提交配置"))

